{*************************************************************************************}
{*                                                                                   *}
{* *************** Norsenet Cryptography Library for 32 bits Systems *************** *}
{*                                                                                   *}
{* File Description: This library implements a set of cryptographic functions, like  *}
{*                   encrypt or decrypt strings or files and calculate the Message   *}
{*                   Digest 5 hash for a string or file (MD5 checksum).              *}
{*                                                                                   *}
{* Copyright (c) 2010 - Willian Jhonnes L. dos Santos                                *}
{* Permission is hereby granted, free of charge, to any person obtaining a copy of   *}
{* this software and associated documentation files (the "Software"), to deal in the *}
{* Software without restriction, including without limitation the rights to use,     *}
{* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the   *}
{* Software, and to permit persons to whom the Software is furnished to do so,       *}
{* subject to the following conditions:                                              *}
{*                                                                                   *}
{* The above copyright notice and this permission notice shall be included in all    *}
{* copies or substantial portions of the Software.                                   *}
{*                                                                                   *}
{* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR        *}
{* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS  *}
{* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR    *}
{* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN *}
{* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION   *}
{* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                   *}
{*                                                                                   *}
{* The software is distributed under the GNU Lesser General Public License, that can *}
{* be found at http://www.gnu.org/copyleft/lesser.html.                              *}
{*                                                                                   *}
{* Comments, contributions and donations can be send directly to the authors by      *}
{* willianjhonnes@yahoo.com.br or willianjhonnes@gmail.com                           *}
{*************************************************************************************}

library nncrypt32;

uses

  { LCL Units }
  Classes,
  SysUtils,

  { DCPCipher Units }
  DCPblowfish,
  DCPcast128,
  DCPcast256,
  DCPdes,
  DCPgost,
  DCPice,
  DCPidea,
  DCPmars,
  DCPmisty1,
  DCPrc2,
  DCPrc4,
  DCPrc5,
  DCPrc6,
  DCPrijndael,
  DCPserpent,
  DCPtea,
  DCPtwofish,

  { DCPHash Units }
  DCPhaval,
  DCPmd4,
  DCPmd5,
  DCPripemd128,
  DCPripemd160,
  DCPsha1,
  DCPsha256,
  DCPsha512,
  DCPtiger, nntypes;

{*************************************************************************************}
{*                                                                                   *}
{* Result codes:                                                                     *}
{*   0: Successful executed                                                          *}
{*  -1: Key String is empty                                                          *}
{*  -2: String is empty                                                              *}
{*  -3: Incorrect type of Cipher selected                                            *}
{*  -4: Incorrect type of Hash selected                                              *}
{*                                                                                   *}
{*************************************************************************************}
function EncryptString(AKeyString, AStr: WideString; ACipher: TCipherType;
  AHash: THashType; var AResult: WideString): Integer; stdcall;
begin
  if AKeyString = '' then
  begin
    Result := -1;
    Exit;
  end;

  if AStr = '' then
  begin
    Result := -2;
    Exit;
  end;

  Result := 0;

  case ACipher of
    ctBlowFish: with TDCP_blowfish.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctCast128 : with TDCP_cast128.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctCast256 : with TDCP_cast256.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctDes     : with TDCP_des.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ct3Des    : with TDCP_3des.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctGost    : with TDCP_gost.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctIce     : with TDCP_ice.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctThinIce : with TDCP_thinice.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctIce2    : with TDCP_ice2.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctIdea    : with TDCP_idea.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctMars    : with TDCP_mars.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctMisty1  : with TDCP_misty1.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctRC2     : with TDCP_rc2.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctRC4     : with TDCP_rc4.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctRC5     : with TDCP_rc5.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctRC6     : with TDCP_rc6.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctRijndael: with TDCP_rijndael.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctSerpent : with TDCP_serpent.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctTea     : with TDCP_tea.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
    ctTwoFish : with TDCP_twofish.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := EncryptString(AStr);
                  Burn;
                  Free;
                end;
  else
    Result := -3;
  end;
end;

{*************************************************************************************}
{*                                                                                   *}
{* Result codes:                                                                     *}
{*   0: Successful executed                                                          *}
{*  -1: Key String is empty                                                          *}
{*  -2: String is empty                                                              *}
{*  -3: Incorrect type of Cipher selected                                            *}
{*  -4: Incorrect type of Hash selected                                              *}
{*                                                                                   *}
{*************************************************************************************}
function DecryptString(AKeyString, AStr: WideString; ACipher: TCipherType;
  AHash: THashType; var AResult: WideString): Integer; stdcall;
begin
  if AKeyString = '' then
  begin
    Result := -1;
    Exit;
  end;

  if AStr = '' then
  begin
    Result := -2;
    Exit;
  end;
  Result := 0;

  case ACipher of
    ctBlowFish: with TDCP_blowfish.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctCast128 : with TDCP_cast128.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctCast256 : with TDCP_cast256.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctDes     : with TDCP_des.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ct3Des    : with TDCP_3des.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctGost    : with TDCP_gost.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctIce     : with TDCP_ice.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctThinIce : with TDCP_thinice.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctIce2    : with TDCP_ice2.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctIdea    : with TDCP_idea.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctMars    : with TDCP_mars.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctMisty1  : with TDCP_misty1.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctRC2     : with TDCP_rc2.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctRC4     : with TDCP_rc4.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctRC5     : with TDCP_rc5.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctRC6     : with TDCP_rc6.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctRijndael: with TDCP_rijndael.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctSerpent : with TDCP_serpent.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctTea     : with TDCP_tea.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
    ctTwoFish : with TDCP_twofish.Create(nil) do
                begin
                  case AHash of
                    htHaval    : InitStr(AKeyString, TDCP_haval);
                    htMD4      : InitStr(AKeyString, TDCP_md4);
                    htMD5      : InitStr(AKeyString, TDCP_md5);
                    htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                    htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                    htSHA1     : InitStr(AKeyString, TDCP_sha1);
                    htSHA256   : InitStr(AKeyString, TDCP_sha256);
                    htSHA384   : InitStr(AKeyString, TDCP_sha384);
                    htSHA512   : InitStr(AKeyString, TDCP_sha512);
                    htTiger    : InitStr(AKeyString, TDCP_tiger);
                  else
                    Result := -4;
                    Exit;
                  end;

                  AResult := DecryptString(AStr);
                  Burn;
                  Free;
                end;
  else
    Result := -3;
  end;
end;

{*************************************************************************************}
{*                                                                                   *}
{* Result codes:                                                                     *}
{*   0: Successful executed                                                          *}
{*  -1: Key String is empty                                                          *}
{*  -2: Source file does not exist                                                   *}
{*  -3: Incorrect type of Cipher selected                                            *}
{*  -4: Incorrect type of Hash selected                                              *}
{*  -5: Path of source file is empty                                                 *}
{*  -6: Path of destination file is empty                                            *}
{*  -7: Cannot open source file                                                      *}
{*  -8: Cannot create destination file                                               *}
{*  -9: Could not encrypt the file stream                                            *}
{*                                                                                   *}
{*************************************************************************************}
function EncryptFile(AKeyString, ASource, ADest: WideString; ACipher: TCipherType;
  AHash: THashType): Integer; stdcall;
var
  rSource, rDest: TFileStream;
begin
  if AKeyString = '' then
  begin
    Result := -1;
    Exit;
  end;

  if ASource = '' then
  begin
    Result := -5;
    Exit;
  end;

  if ADest = '' then
  begin
    Result := -6;
    Exit;
  end;

  if not FileExists(ASource) then
  begin
    Result := -2;
    Exit;
  end;

  try
    rSource := TFileStream.Create(ASource, fmOpenRead);
  except
    Result := -7;
    Exit;
  end;

  try
    rDest := TFileStream.Create(ADest, fmCreate);
  except
    Result := -8;
    Exit;
  end;

  Result := 0;

  try
    case ACipher of
      ctBlowFish: with TDCP_blowfish.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctCast128 : with TDCP_cast128.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctCast256 : with TDCP_cast256.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctDes     : with TDCP_des.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ct3Des    : with TDCP_3des.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctGost    : with TDCP_gost.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctIce     : with TDCP_ice.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctThinIce : with TDCP_thinice.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctIce2    : with TDCP_ice2.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctIdea    : with TDCP_idea.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctMars    : with TDCP_mars.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctMisty1  : with TDCP_misty1.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctRC2     : with TDCP_rc2.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctRC4     : with TDCP_rc4.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctRC5     : with TDCP_rc5.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctRC6     : with TDCP_rc6.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctRijndael: with TDCP_rijndael.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctSerpent : with TDCP_serpent.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctTea     : with TDCP_tea.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctTwoFish : with TDCP_twofish.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    EncryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
    else
      Result := -3;
    end;
  except
    Result := -9;
  end;

  FreeAndNil(rSource);
  FreeAndNil(rDest);
end;

{*************************************************************************************}
{*                                                                                   *}
{* Result codes:                                                                     *}
{*   0: Successful executed                                                          *}
{*  -1: Key String is empty                                                          *}
{*  -2: Source file does not exist                                                   *}
{*  -3: Incorrect type of Cipher selected                                            *}
{*  -4: Incorrect type of Hash selected                                              *}
{*  -5: Path of source file is empty                                                 *}
{*  -6: Path of destination file is empty                                            *}
{*  -7: Cannot open source file                                                      *}
{*  -8: Cannot create destination file                                               *}
{*  -9: Could not decrypt the file stream                                            *}
{*                                                                                   *}
{*************************************************************************************}
function DecryptFile(AKeyString, ASource, ADest: WideString; ACipher: TCipherType;
  AHash: THashType): Integer; stdcall;
var
  rSource, rDest: TFileStream;
begin
  if AKeyString = '' then
  begin
    Result := -1;
    Exit;
  end;

  if ASource = '' then
  begin
    Result := -5;
    Exit;
  end;

  if ADest = '' then
  begin
    Result := -6;
    Exit;
  end;

  if not FileExists(ASource) then
  begin
    Result := -2;
    Exit;
  end;

  try
    rSource := TFileStream.Create(ASource, fmOpenRead);
  except
    Result := -7;
    Exit;
  end;

  try
    rDest := TFileStream.Create(ADest, fmCreate);
  except
    Result := -8;
    Exit;
  end;

  Result := 0;

  try
    case ACipher of
      ctBlowFish: with TDCP_blowfish.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctCast128 : with TDCP_cast128.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctCast256 : with TDCP_cast256.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctDes     : with TDCP_des.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ct3Des    : with TDCP_3des.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctGost    : with TDCP_gost.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctIce     : with TDCP_ice.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctThinIce : with TDCP_thinice.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctIce2    : with TDCP_ice2.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctIdea    : with TDCP_idea.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctMars    : with TDCP_mars.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctMisty1  : with TDCP_misty1.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctRC2     : with TDCP_rc2.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctRC4     : with TDCP_rc4.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctRC5     : with TDCP_rc5.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctRC6     : with TDCP_rc6.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctRijndael: with TDCP_rijndael.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctSerpent : with TDCP_serpent.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctTea     : with TDCP_tea.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
      ctTwoFish : with TDCP_twofish.Create(nil) do
                  begin
                    case AHash of
                      htHaval    : InitStr(AKeyString, TDCP_haval);
                      htMD4      : InitStr(AKeyString, TDCP_md4);
                      htMD5      : InitStr(AKeyString, TDCP_md5);
                      htRipemd128: InitStr(AKeyString, TDCP_ripemd128);
                      htRipemd160: InitStr(AKeyString, TDCP_ripemd160);
                      htSHA1     : InitStr(AKeyString, TDCP_sha1);
                      htSHA256   : InitStr(AKeyString, TDCP_sha256);
                      htSHA384   : InitStr(AKeyString, TDCP_sha384);
                      htSHA512   : InitStr(AKeyString, TDCP_sha512);
                      htTiger    : InitStr(AKeyString, TDCP_tiger);
                    else
                      Result := -4;
                      Exit;
                    end;

                    DecryptStream(rSource, rDest, rSource.Size);
                    Burn;
                    Free;
                  end;
    else
      Result := -3;
    end;
  except
    Result := -9;
  end;

  FreeAndNil(rSource);
  FreeAndNil(rDest);
end;

{*************************************************************************************}
{*                                                                                   *}
{* Result codes:                                                                     *}
{*   0: Successful executed                                                          *}
{*  -1: String is empty                                                              *}
{*  -2: Could not calculate the MD5 Checksum of the string                           *}
{*                                                                                   *}
{*************************************************************************************}
function MD5String(AStr: WideString; var ACheckSum: WideString): Integer; stdcall;
var
  rHash: TDCP_md5;
  rDigest: array[0..31] of Byte;
  i: Byte;
begin
  if AStr = '' then
  begin
    Result := -1;
    Exit;
  end;

  for i := 0 to 31 do
    rDigest[i] := $00;

  try
    rHash := TDCP_md5.Create(nil);
    rHash.Init;
    rHash.UpdateStr(AStr);
    rHash.Final(rDigest);
    rHash.Free;
    Result := 0;

    ACheckSum := '';
    for i := 0 to 31 do
      ACheckSum := ACheckSum + IntToHex(rDigest[i], 2);

    ACheckSum := Copy(LowerCase(ACheckSum), 1, 32);
  except
    rHash.Free;
    Result := -2;
  end;
end;

{*************************************************************************************}
{*                                                                                   *}
{* Result codes:                                                                     *}
{*   0: Successful executed                                                          *}
{*  -1: Path of source file is empty                                                 *}
{*  -2: Source file does not exist                                                   *}
{*  -3: Cannot open source file                                                      *}
{*  -4: Could not calculate the MD5 Checksum of the source file                      *}
{*                                                                                   *}
{*************************************************************************************}
function MD5File(ASource: WideString; var ACheckSum: WideString): Integer; stdcall;
var
  rHash: TDCP_md5;
  rSource: TFileStream;
  rDigest: array[0..31] of Byte;
  i: Byte;
begin
  if ASource = '' then
  begin
    Result := -1;
    Exit;
  end;

  if not FileExists(ASource) then
  begin
    Result := -2;
    Exit;
  end;

  for i := 0 to 31 do
    rDigest[i] := $00;

  try
    rSource := TFileStream.Create(ASource, fmOpenRead);
    Result := 0;
  except
    Result := -3;
    Exit;
  end;

  try
    rHash := TDCP_md5.Create(nil);
    rHash.Init;
    rHash.UpdateStream(rSource, rSource.Size);
    rHash.Final(rDigest);
    rHash.Free;
    rSource.Free;

    ACheckSum := '';
    for i := 0 to 31 do
      ACheckSum := ACheckSum + IntToHex(rDigest[i], 2);

    ACheckSum := Copy(LowerCase(ACheckSum), 1, 32);
  except
    Result := -4;
    rHash.Free;
    rSource.Free;
  end;
end;

exports
  EncryptString,
  DecryptString,
  EncryptFile,
  DecryptFile,
  MD5String,
  MD5File;

{$IFDEF WINDOWS}{$R nncrypt32.rc}{$ENDIF}

begin
end.

